package com.summer.data.jql.table;

import com.summer.data.Jsql;
import com.summer.data.dialect.Dialect;
import com.summer.data.jql.Context;
import com.summer.data.jql.concept.Field;
import com.summer.data.table.BaseColumn;

/**
 * @author 345480567@qq.com
 * todo: 这个类可能有问题
 */
public class ColumnedJqlColumn<T> implements Field<T> {

    JqlTable host;
    BaseColumn<T> column;

    public ColumnedJqlColumn(JqlTable host, BaseColumn<T> column) {
        this.host = host;
        this.column = column;
    }

    @Override
    public Jsql toFieldSql(Context ctx, Dialect dialect) {
        String format = "%s.%s";
        String alias = ctx.getAlias(host);
        return Jsql.format(format, alias, column.colName);
    }
}
